<?php
/**
 * Created by PhpStorm.
 * User: zq
 * Date: 2018/2/9
 * Time: 09:19
 */

namespace Helper;
class ErrorCode {

    //http://open.weibo.com/wiki/Error_code

    public const SUCCESS             = 200;
    public const ERROR_SYSTEM        = 10001;
    public const ERROR_PARAMS        = 20001;
    public const ERROR_TOKEN         = 20002;
    public const ERROR_MOBILE        = 20003;
    public const ERROR_SMSCODE       = 20004;
    public const ERROR_SENDSMS       = 20005;
    public const ERROR_PASSWORD      = 20006;
    public const ERROR_CLASS         = 20007;
    public const ERROR_CLASSNAME_LEN = 20008;
    public const FAIL_LOGIN          = 20009;
    public const NOT_VALID_PASSWORD  = 20010;
    public const NOT_VALID_SMSCODE   = 20011;
    public const NULL_PARAMS         = 20012;
    public const NULL_USER           = 20013;
    public const MOBILE_REGIDTER     = 20014;
    public const CLASS_FULL          = 20015;
    public const EXIST_CLASS_STUDENT = 20016;
    public const ERROR_UPLOAD        = 20017;
    public const CLASS_NO            = 20018;
    public const ERROR_REGISTER      = 20019;
    public const ERROR_CREATE_CLASS  = 20020;

    public const HOMEWORK_NO_SUBMIT             = 20101;
    public const HOMEWORK_STUDENT_CORRECTED     = 20102;
    public const HOMEWORK_PARAMS_QUESTION_ID_NO = 20103;


    private const ERRINFO = [
        self::SUCCESS             => '成功',
        self::ERROR_SYSTEM        => '系统错误',
        self::ERROR_PARAMS        => '参数错误',
        self::ERROR_TOKEN         => 'token有误',
        self::ERROR_MOBILE        => '手机号有误',
        self::ERROR_SMSCODE       => '验证码填写有误',
        self::ERROR_SENDSMS       => '短信发送失败',
        self::ERROR_PASSWORD      => '原密码错误',
        self::ERROR_CLASS         => '班级号有误',
        self::ERROR_CLASSNAME_LEN => '班级名称不能超过10个字',
        self::FAIL_LOGIN          => '账号密码不符！请重新输入',
        self::NOT_VALID_PASSWORD  => '密码格式不符合要求',
        self::NOT_VALID_SMSCODE   => '短信验证码格式不符合要求',
        self::NULL_PARAMS         => '参数为空',
        self::NULL_USER           => '用户不存在',
        self::MOBILE_REGIDTER     => '手机号已被注册',
        self::CLASS_FULL          => '创建班级数目已满',
        self::EXIST_CLASS_STUDENT => '已经加入该班级',
        self::CLASS_NO            => '未加入任何班级',
        self::ERROR_UPLOAD        => '上传失败',
        self::ERROR_REGISTER      => '注册失败',
        self::ERROR_CREATE_CLASS  => '创建班级失败',

        self::HOMEWORK_NO_SUBMIT             => '作业未提交',
        self::HOMEWORK_STUDENT_CORRECTED     => '该学生作业已批改完毕，不能再次修改',
        self::HOMEWORK_PARAMS_QUESTION_ID_NO => '学生的答题数据中没有本道题',


    ];


    public static function info($code = self::SUCCESS) {
        $code = isset(self::ERRINFO[$code]) ? $code : self::SUCCESS;
        return ['code' => $code, 'message' => self::ERRINFO[$code]];
    }

    public static function getMsg($code = self::SUCCESS) {
        $code = isset(self::ERRINFO[$code]) ? $code : self::SUCCESS;
        return self::ERRINFO[$code];
    }

}